<template>
  <el-row :gutter="40" class="panel-group">
    <el-col :xs="12" :sm="12" :lg="6" v-if="getValidType('代理管理')" class="card-panel-col">
      <div class="card-panel" @click="handleSetLineChartData('newVisitis')">
        <div class="card-panel-icon-wrapper icon-people" @click="$router.push('/agent')">
          <svg-icon name="tree" class="card-panel-icon" />
        </div>
        <div class="card-panel-description">
          <div class="card-panel-text">
            <span class="red-text">
              代理总数
              {{ tempData['代理管理']?.totalCount || '0' }}
            </span>
          </div>
          <div class="card-panel-text">
            本月新增
            {{ tempData['代理管理']?.monthCount || '0' }}
          </div>
          <div class="card-panel-text">
            本周新增
            {{ tempData['代理管理']?.weekCount || '0' }}
          </div>
          <div class="card-panel-text">
            本日新增
            {{ tempData['代理管理']?.dayCount || '0' }}
          </div>
          <div class="card-panel-text">
            七日活跃
            {{ tempData['代理管理']?.weekCount || '0' }}
          </div>
        </div>
      </div>
    </el-col>
    <el-col :xs="12" :sm="12" :lg="6" v-if="getValidType('客服管理')" class="card-panel-col">
      <div class="card-panel" @click="handleSetLineChartData('messages')">
        <div class="card-panel-icon-wrapper icon-message" @click="$router.push('/customer')">
          <svg-icon name="people" class="card-panel-icon" />
        </div>
        <div class="card-panel-description">
          <div class="card-panel-text">
            <span class="red-text">
              客服总数
              {{ tempData['客服管理']?.totalCount || '0' }}
            </span>
          </div>
          <div class="card-panel-text">
            本月新增
            {{ tempData['客服管理']?.monthCount || '0' }}
          </div>
          <div class="card-panel-text">
            本周新增
            {{ tempData['客服管理']?.weekCount || '0' }}
          </div>
          <div class="card-panel-text">
            本日新增
            {{ tempData['客服管理']?.dayCount || '0' }}
          </div>
          <div class="card-panel-text">
            七日活跃
            {{ tempData['客服管理']?.weekCount || '0' }}
          </div>
        </div>
      </div>
    </el-col>
    <el-col :xs="12" :sm="12" :lg="6" v-if="getValidType('下属用户')" class="card-panel-col">
      <div class="card-panel" @click="handleSetLineChartData('purchases')">
        <div class="card-panel-icon-wrapper icon-money" @click="$router.push('/user/junior')">
          <svg-icon name="peoples" class="card-panel-icon" />
        </div>
        <div class="card-panel-description">
          <div class="card-panel-text">
            <span class="red-text">
              下属用户
              {{ tempData['下属用户']?.totalCount || '0' }}
            </span>
          </div>
          <div class="card-panel-text">
            本月新增
            {{ tempData['下属用户']?.monthCount || '0' }}
          </div>
          <div class="card-panel-text">
            本周新增
            {{ tempData['下属用户']?.weekCount || '0' }}
          </div>
          <div class="card-panel-text">
            本日新增
            {{ tempData['下属用户']?.dayCount || '0' }}
          </div>
          <div class="card-panel-text">
            七日活跃
            {{ tempData['下属用户']?.weekCount || '0' }}
          </div>
        </div>
      </div>
    </el-col>
    <el-col :xs="12" :sm="12" :lg="6" v-if="getValidType('直属用户')" class="card-panel-col">
      <div class="card-panel" @click="handleSetLineChartData('shoppings')">
        <div class="card-panel-icon-wrapper icon-shopping" @click="$router.push('/user/direct')">
          <svg-icon name="user" class="card-panel-icon" />
        </div>
        <div class="card-panel-description">
          <div class="card-panel-text">
            <span class="red-text">
              直属用户
              {{ tempData['直属用户']?.totalCount || '0' }}
            </span>
          </div>
          <div class="card-panel-text">
            本月新增
            {{ tempData['直属用户']?.monthCount || '0' }}
          </div>
          <div class="card-panel-text">
            本周新增
            {{ tempData['直属用户']?.weekCount || '0' }}
          </div>
          <div class="card-panel-text">
            本日新增
            {{ tempData['直属用户']?.dayCount || '0' }}
          </div>
          <div class="card-panel-text">
            七日活跃
            {{ tempData['直属用户']?.weekCount || '0' }}
          </div>
        </div>
      </div>
    </el-col>
  </el-row>
</template>

<script lang="ts">
import { getCounts } from '@/api/admin';
import { Component, Vue } from 'vue-property-decorator';
import { ManagerModule } from '@/store/modules/manager';
@Component({
  name: 'PanelGroup'
})
export default class extends Vue {
  public tempData = {};
  async created() {
    const ret = await getCounts();
    if (ret?.status) {
      this.tempData = ret.data;
    }
  }
  public getValidType(type: TRole.RoleType): boolean {
    const temp = ManagerModule?.roles[type];
    if (temp) {
      return true;
    } else {
      return false;
    }
  }
  handleSetLineChartData(type: string) {
    this.$emit('handle-set-line-chart-data', type);
  }
}
</script>

<style lang="scss" scoped>
.red-text {
  color: red; /* 设置该部分文字为红色 */
}
.panel-group {
  margin-top: 18px;
  .card-panel-col {
    margin-bottom: 32px;
  }

  .card-panel {
    height: 180px;
    cursor: pointer;
    font-size: 12px;
    position: relative;
    overflow: hidden;
    color: #666;
    background: #fff;
    box-shadow: 4px 4px 40px rgba(0, 0, 0, 0.05);
    border-color: rgba(0, 0, 0, 0.05);

    &:hover {
      .card-panel-icon-wrapper {
        color: #fff;
      }

      .icon-people {
        background: #40c9c6;
      }

      .icon-message {
        background: #36a3f7;
      }

      .icon-money {
        background: #f4516c;
      }

      .icon-shopping {
        background: #34bfa3;
      }
    }

    .icon-people {
      color: #40c9c6;
    }

    .icon-message {
      color: #36a3f7;
    }

    .icon-money {
      color: #f4516c;
    }

    .icon-shopping {
      color: #34bfa3;
    }

    .card-panel-icon-wrapper {
      float: left;
      margin: 14px 0 0 14px;
      padding: 16px;
      transition: all 0.38s ease-out;
      border-radius: 6px;
    }

    .card-panel-icon {
      float: left;
      font-size: 58px;
    }

    .card-panel-description {
      float: right;
      font-weight: bold;
      margin: 10px;
      margin-left: 0px;

      .card-panel-text {
        line-height: 18px;
        color: rgba(0, 0, 0, 0.45);
        font-size: 16px;
        margin-bottom: 15px;
      }

      .card-panel-num {
        font-size: 20px;
      }
    }
  }
}

@media (max-width: 550px) {
  .card-panel-description {
    display: none;
  }

  .card-panel-icon-wrapper {
    float: none !important;
    width: 100%;
    height: 100%;
    margin: 0 !important;

    .svg-icon {
      display: block;
      margin: 14px auto !important;
      float: none !important;
    }
  }
}
</style>
